package com.xt.controller;

import com.xt.bean.Module;
import com.xt.bean.PlatformResult;
import com.xt.service.ModuleService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by XT on 2018/5/4.
 */
@RestController
@RequestMapping(value = "/module")
public class ModuleController {

    @Autowired
    private ModuleService ms;

    @ApiOperation(value = "模块列表", notes = "查询模块列表")
    @RequestMapping(value = "/list")
    public PlatformResult list(@ApiParam(required = true, name = "pageNo", value = "当前页") int count,
                               @ApiParam(required = true, name = "count", value = "每页条数") int pageNo,
                               @ApiParam(required = true, name = "sortDirection", value = "排序方式（asc/desc）") String sortDirection,
                               @ApiParam(required = true, name = "sortField", value = "排序字段") String[] sortField) {
        Page<Module> page = ms.getAllModuleListByPage(count, pageNo, sortDirection, sortField);
        return PlatformResult.ok(page);
    }

    @ApiOperation(value = "插入或修改模块", notes = "插入或修改模块")
    @RequestMapping(value = "/save")
    public PlatformResult save(@ApiParam(required = true, name = "module", value = "Module实体的字段名") Module module) {
        ms.saveOrUpdateModule(module);
        return PlatformResult.ok();
    }


    @ApiOperation(value = "删除模块", notes = "插入或修改模块")
    @RequestMapping(value = "/delete")
    public PlatformResult delete(@ApiParam(required = true, name = "module", value = "Module实体的字段名") Module module) {
        ms.deleteModule(module.getId());
        return PlatformResult.ok();
    }

}
